﻿cmake_minimum_required(VERSION 3.20)
project(qt_widget)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOMOC ON)

file(GLOB SOURCE "*.cpp" "*.c" "*.cc")
file(GLOB HEAD "*.h" "*.hpp")
file(GLOB QT "*.qrc" "*.ui")
add_executable(${PROJECT_NAME} WIN32 
	${SOURCE}
	${HEAD}
        ${QT}
        logo.rc
)

# OFF Qt5  ON Qt6
set(QT_V OFF)

if(QT_V)
# Qt6
find_package(Qt6 COMPONENTS Quick Widgets QuickControls2 REQUIRED)
target_link_libraries(${PROJECT_NAME}
	Qt6::Quick
	Qt6::Widgets
	Qt6::QuickControls2
)
else()
# Qt5
find_package(Qt5 COMPONENTS Widgets REQUIRED)
target_link_libraries(${PROJECT_NAME}
	Qt5::Widgets
)
endif()

# 生成bin输出到统一目录，""给linux DEBUG、RELEASE给windows
# 其余lib、pdb不影响按默认
set(RUNTIME "${CMAKE_CURRENT_LIST_DIR}/bin")
set_target_properties(${PROJECT_NAME} PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY ${RUNTIME}
    RUNTIME_OUTPUT_DIRECTORY_DEBUG ${RUNTIME}
    RUNTIME_OUTPUT_DIRECTORY_RELEASE ${RUNTIME}
)

# 新建一个空白的main.cpp, 首次使用QtCreate打开，生成一些必要文件更方便

# 为了find_package查找路径，设置如下: (-D 也可以多次设置)
# set(Qt6_DIR C:\Qt\6.5.3\msvc2019_64\lib\cmake\Qt6)
# cmake -S . -B build -D Qt6_DIR=C:\Qt\6.5.3\msvc2019_64\lib\cmake\Qt6
# cmake -S . -B build -D CMAKE_PREFIX_PATH=C:\Qt\6.5.3\msvc2019_64\lib\cmake\Qt6

# -A x64  -A Win32
# cmake -S . -B build -A  -D CMAKE_PREFIX_PATH=
# 这里设置了config，install时就不需要了
# cmake --build build --config Release
# vs运行还需要把依赖库整过来
# C:\Qt\6.5.3\msvc2019_64\bin\windeployqt ${PROJECT_NAME}.exe
